package com.hjh.java.rabbitmq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Slf4j
@Configuration
public class RabbitmqConfig2 {

    @Autowired
    private Environment env;

    //===============验证topic Exchange的队列==========
    @Bean
    public Queue importQueue() {
        String queueName = env.getProperty("zhcz.pareq.import.queue", "queue.name.import");
        log.info("|queueName:{}", queueName);
        return new Queue(queueName);
    }

    @Bean
    TopicExchange importExchange() {
        String exchange = env.getProperty("zhcz.pareq.import.exchange", "exchange.name.import");
        log.info("|exchange:{}", exchange);
        return new TopicExchange(exchange);
    }

    /**
     * 绑定
     *
     * @return
     */
    @Bean
    Binding bindingImport() {
        String routingKey = env.getProperty("zhcz.pareq.import.routingKey", "routingKey.name.import");
        log.info("|routingKey:{}", routingKey);
        return BindingBuilder.bind(importQueue()).to(importExchange()).with(routingKey);
    }
}
